/**
 *
 */
package commons.beancopier.annotationimpl;

import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.List;

import com.tmall.common.beancopier.SameBeanPropertyMapperImpl;
import com.tmall.common.beancopier.mapper.AbstractPropertiesMapperBuilder;
import com.tmall.common.beancopier.mapper.PropertiesMapper;


/**
 * @author 陌铭(Phenix Huang)
 *
 */
public class AnnotationBasedPropMapperBuilder extends AbstractPropertiesMapperBuilder {

    public AnnotationBasedPropMapperBuilder() {
    }

    /*
     * @see net.phenix.comp.util.bean.AbstractClassMapper#needHandle(java.lang.Class)
     */
    @Override
    public boolean needToExclude(Class<?> clz) {
        return clz.getAnnotation(BeanExcludeCopyFlag.class) != null ;
    }

    /*
     * @see net.phenix.comp.util.bean.AbstractClassMapper#createMapper(java.lang.Class)
     */
    @Override
    public PropertiesMapper createMapper(Class<?> clz) {
        Field[] fields = clz.getDeclaredFields();
        List<String> propertyNames = new ArrayList<String>(fields.length);
        for (Field field : fields) {
            if (field.getAnnotation(PropertyExcludeCopyFlag.class) != null ) {
                continue ;
            }
            propertyNames.add(field.getName());
        }
        return new SameBeanPropertyMapperImpl(propertyNames);
    }


}
